"use strict"

const nodemailer = require('nodemailer');

let sendMail = (dataObj, callback) => {

    let transporter = nodemailer.createTransport({
        host: 'smtp.exmail.qq.com',
        port: 25,
        secure: false, // true for 465, false for other ports
        auth: {
            user: 'zzgg@wisedu.com', // generated ethereal user
            pass: 'WISedu@12345' // generated ethereal password
        }
    });

    // setup email data with unicode symbols
    let mailOptions = {
        from: 'zzgg@wisedu.com', // sender address
        to: dataObj.to, // list of receivers
        subject: dataObj.subject, // Subject line
        cc: 'jlgao@wisedu.com,lyzhu@wisedu.com,jwhu@wisedu.com,juanzhang@wisedu.com,xjwang@wisedu.com',
        html: dataObj.html // html body
    };

    // send mail with defined transport object
    transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
            console.log('邮件发送失败!!!!!!!');
            console.log(error);
            callback(1);
            return;
        }

        console.log('邮件发送成功!!');
        if (typeof callback === 'function') {
            callback(1);
        }
    });

};

exports.sendMail = sendMail;